<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="交易号" prop="zfJyid">
        <el-input
          v-model="queryParams.zfJyid"
          placeholder="请输入交易号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="ddId">
        <el-input
          v-model="queryParams.ddId"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="订单号" prop="zhDdid">-->
<!--        <el-input-->
<!--          v-model="queryParams.zhDdid"-->
<!--          placeholder="请输入订单号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="昵称名称" prop="zhName">-->
<!--        <el-input-->
<!--          v-model="queryParams.zhName"-->
<!--          placeholder="请输入昵称名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="应付款" prop="zfYingfukuan">-->
<!--        <el-input-->
<!--          v-model="queryParams.zfYingfukuan"-->
<!--          placeholder="请输入应付款"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="支付方式" prop="zfZhifufangshi">-->
<!--        <el-input-->
<!--          v-model="queryParams.zfZhifufangshi"-->
<!--          placeholder="请输入支付方式"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="实付款" prop="zfShifukuan">-->
<!--        <el-input-->
<!--          v-model="queryParams.zfShifukuan"-->
<!--          placeholder="请输入实付款"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建时间" prop="zfCreatetime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.zfCreatetime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择创建时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="完成时间" prop="zfWangchengtime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.zfWangchengtime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择完成时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="支付账户UUID" prop="zfUuid">-->
<!--        <el-input-->
<!--          v-model="queryParams.zfUuid"-->
<!--          placeholder="请输入支付账户UUID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['caiwu:zhifu:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['caiwu:zhifu:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['caiwu:zhifu:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['caiwu:zhifu:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="zhifuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="支付ID" align="center" prop="zfId" />
      <el-table-column label="订单类型" align="center" prop="dingdan.ddfenlei.ddflName" />
      <el-table-column label="交易号" align="center" prop="zfJyid" />
      <el-table-column label="昵称名称" align="center" width="150">
        <template slot-scope="scope">
          <div class="zhifu">
            <p style="color: black;margin: 0;padding: 0">{{scope.row.dingdan.yonghu.yhName}}</p>
            <p style="color: #bbbbbb;margin: 0;padding: 0">+86{{scope.row.dingdan.yonghu.yhPhone}}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="应付款" align="center" prop="dingdan.ddYingfu" />
      <el-table-column label="支付方式" align="center" prop="dingdan.ddZhifufangshi" />
      <el-table-column label="实付款" align="center" prop="dingdan.ddShifu" />
      <el-table-column label="创建时间" align="center" prop="dingdan.ddAddtime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zfCreatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="zfWangchengtime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zfWangchengtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="zfZhuangtai" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['caiwu:zhifu:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['caiwu:zhifu:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改支付记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="交易号" prop="zfJyid">
          <el-input v-model="form.zfJyid" placeholder="请输入交易号" />
        </el-form-item>
        <el-form-item label="订单号" prop="zhDdid">
          <el-input v-model="form.zhDdid" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="昵称名称" prop="zhName">
          <el-input v-model="form.zhName" placeholder="请输入昵称名称" />
        </el-form-item>
        <el-form-item label="应付款" prop="zfYingfukuan">
          <el-input v-model="form.zfYingfukuan" placeholder="请输入应付款" />
        </el-form-item>
        <el-form-item label="支付方式" prop="zfZhifufangshi">
          <el-input v-model="form.zfZhifufangshi" placeholder="请输入支付方式" />
        </el-form-item>
        <el-form-item label="实付款" prop="zfShifukuan">
          <el-input v-model="form.zfShifukuan" placeholder="请输入实付款" />
        </el-form-item>
        <el-form-item label="创建时间" prop="zfCreatetime">
          <el-date-picker clearable
            v-model="form.zfCreatetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="完成时间" prop="zfWangchengtime">
          <el-date-picker clearable
            v-model="form.zfWangchengtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单ID" prop="ddId">
          <el-input v-model="form.ddId" placeholder="请输入订单ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listZhifu, getZhifu, delZhifu, addZhifu, updateZhifu } from "@/api/caiwu/zhifu";

export default {
  name: "Zhifu",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支付记录表格数据
      zhifuList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zfJyid: null,
        zfDingdantype: null,
        zfYonghutype: null,
        zhDdid: null,
        zhName: null,
        zfYingfukuan: null,
        zfZhifufangshi: null,
        zfShifukuan: null,
        zfCreatetime: null,
        zfWangchengtime: null,
        zfUuid: null,
        zfZhuangtai: null,
        ddId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // zfJyid: [
        //   { required: true, message: "交易号不能为空", trigger: "blur" }
        // ],
        // zfDingdantype: [
        //   { required: true, message: "订单类型不能为空", trigger: "change" }
        // ],
        // zfYonghutype: [
        //   { required: true, message: "用户类型不能为空", trigger: "change" }
        // ],
        // zhDdid: [
        //   { required: true, message: "订单号不能为空", trigger: "blur" }
        // ],
        // zhName: [
        //   { required: true, message: "昵称名称不能为空", trigger: "blur" }
        // ],
        // zfYingfukuan: [
        //   { required: true, message: "应付款不能为空", trigger: "blur" }
        // ],
        // zfZhifufangshi: [
        //   { required: true, message: "支付方式不能为空", trigger: "blur" }
        // ],
        // zfShifukuan: [
        //   { required: true, message: "实付款不能为空", trigger: "blur" }
        // ],
        // zfCreatetime: [
        //   { required: true, message: "创建时间不能为空", trigger: "blur" }
        // ],
        // zfUuid: [
        //   { required: true, message: "支付账户UUID不能为空", trigger: "blur" }
        // ],
        // zfZhuangtai: [
        //   { required: true, message: "状态不能为空", trigger: "blur" }
        // ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询支付记录列表 */
    getList() {
      this.loading = true;
      listZhifu(this.queryParams).then(response => {
        console.log(response.rows);
        this.zhifuList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        zfId: null,
        zfJyid: null,
        zfDingdantype: null,
        zfYonghutype: null,
        zhDdid: null,
        zhName: null,
        zfYingfukuan: null,
        zfZhifufangshi: null,
        zfShifukuan: null,
        zfCreatetime: null,
        zfWangchengtime: null,
        zfUuid: null,
        zfZhuangtai: null,
        ddId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.zfId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加支付记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const zfId = row.zfId || this.ids
      getZhifu(zfId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改支付记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.zfId != null) {
            updateZhifu(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZhifu(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const zfIds = row.zfId || this.ids;
      this.$modal.confirm('是否确认删除支付记录编号为"' + zfIds + '"的数据项？').then(function() {
        return delZhifu(zfIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('caiwu/zhifu/export', {
        ...this.queryParams
      }, `zhifu_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.zhifu{
  text-align: left !important;
}
</style>
